<template>
  <div id="land">  

    <div  style="display:flex;margin-bottom:10px;align-items: center;">
            <img class="top_img" src="@/assets/images/a8.png" style="width:35px;height:35px;margin-right:10px;"/>
            <div style="line-height: 40px;font-weight:bold:">金蜜兑换</div>
     </div> 
   <el-form ref="form" label-width="70px" style="width:100%;">
     <div style="display:flex;align-items: center;">
            <div style="width:50px;text-align-last: justify;margin-top:-12px;font-size: 14px;color: #606266;margin-right:10px;">筛选项</div> 

             <el-form-item label="生成时间"   >
                    <el-date-picker  type="date"   placeholder="选择日期" format="yyyy-MM-dd" value-format="yyyy-MM-dd"  v-model="search_form.onedate" style="width:140px;"> 
                    </el-date-picker>
              </el-form-item>

             <el-form-item label="订单类别" style="margin-left:10px;" >
                <el-select  v-model="search_form.select_num" placeholder="订单类别" style="width:140px;">
                    <el-option  v-for="(item,index) in from.pitch_list" :key="index" :label="item.title" :value="item.maid"></el-option>
                </el-select>
             </el-form-item>


 
            <div class="buttoon_box">
                <div class="buttoon_box_item"  style="margin-left:10px;background:#FFC600;color:white;" @click="search_but()">确 定</div>
                <div class="buttoon_box_item" style="margin-left:10px;border:1px solid #D9D9D9;" @click="sx_but()">清 空</div>    
            </div>
     </div>

    <el-row>
        <el-col :span="24" style="text-align: right;">    
            <el-button type="primary" class="custom_color_button1" style="margin-bottom:10px;" @click="people_but">
              <img class="custom_color_button1_img" src="@/assets/images/but_bg7.png" />{{ variable_name2 }}券持有:{{ jindoujuan }}
            </el-button>     
            <el-button type="primary" class="custom_color_button1" style="margin-bottom:10px;" @click="land_but">
              <img class="custom_color_button1_img" src="@/assets/images/but_bg8.png" />生成标的
            </el-button> 
            <el-button type="primary" class="custom_color_button1" style="margin-bottom:10px;" @click="go_land_xq()">
              <img class="custom_color_button1_img" src="@/assets/images/but_bg9.png" />兑换查询
            </el-button>        
        </el-col>
     </el-row>

      </el-form>

   <!-- 渲染数据list -->
   <land-list :landdata="landdata" @up_list_fun="list_fun"> </land-list>

      
   <div style="margin-top:20px;text-align: center;">
      <el-pagination
        background
        @current-change="handleCurrentChange"
        :page-size="10"  
        layout="prev, pager, next, jumper"
        :total="count">
      </el-pagination>
    </div>
   

      <!-- 生成果种 -->
        <el-dialog :title="'生成标的'" :visible.sync="mtk1"  width="40%">
            <div style="width:100%;"> 
           
            <el-form ref="form" label-width="100px" style="width:80%;">
     
                <el-row> 
       

                   <el-form-item :label="variable_name4 + '等级'">
                       <el-select   v-model="from.pitchsrc" placeholder="选择等级" @change="select_change" style="width:100%;">
                            <el-option v-for="(item,index) in from.pitch_list" :key="index"  :label="item.title" :value="item.maid">
                            </el-option>
                       </el-select>   
                    </el-form-item> 

                    <el-form-item :label="item.title" v-for="(item,index) in from.pitch_list" :key="index" >
                        <el-input v-model.number="item.number" placeholder="必填" :disabled="item.type" @input="change_input($event)"></el-input>
                    </el-form-item>
       
                   
                
                    <el-form-item label="时间区间">
                            <el-col :span="11">
                                    <el-time-picker placeholder="选择时间"   format="HH:mm" value-format="HH:mm" v-model="from.time1" style="width: 100%;"></el-time-picker>
                            </el-col>
                            <el-col class="line" :span="2" style="text-align: center;">-</el-col>
                            <el-col :span="11">
                                    <el-time-picker placeholder="选择时间"   format="HH:mm" value-format="HH:mm" v-model="from.time2" style="width: 100%;"></el-time-picker>
                            </el-col>
                    </el-form-item> 


                     <el-form-item label="兑换次数"   >
                        <el-input v-model.number="from.exchange_times" placeholder="必填" ></el-input>
                    </el-form-item> 

                </el-row> 

            </el-form>

                <div style="text-align: center;width:50%;margin:auto;">
                    <el-button type="primary" style="width:80%;"  @click="sub_but">确认</el-button>
                </div>

            </div> 
        </el-dialog>


      <el-dialog title="用户验证" :visible.sync="user_test.user_mtk"  width="400px" >
            <el-form ref="form" :model="user_test"  label-width="100px" style="width:100%;">
                  <el-form-item label="" label-width="0px">
                      <el-input v-model="user_test.password" placeholder="二级密码" ></el-input>
                  </el-form-item>
                  <el-form-item label="" label-width="0px" >
                      <div style="display:flex;">
                          <el-input v-model="user_test.phone" placeholder="手机验证码" style="flex:1;"></el-input>
                           <el-button class="code_but1 custom_color_button" type="primary"  @click="getCode_yz()" :disabled="user_test.disabled" style="margin-left:10px;">
                          {{ user_test.codeText }}
                        </el-button>
                      </div>
                  </el-form-item>
                  <div style="text-align: center;width:50%;margin:auto;margin-top:20px;">
                    <el-button type="primary" class="custom_color_button" style="width:100%;" @click="user_mtk_but">确认</el-button>
                  </div>
          </el-form>
    </el-dialog> 
    

      <!-- 金豆券人数 -->
        <el-dialog :title="variable_name2 + '券人数'" :visible.sync="people_mtk"  width="400px">
            <div style="width:100%;"> 
           
                <el-form ref="form" :model="from"   label-width="100px" style="width:80%;">
     
                  <el-row> 


                    <el-form-item :label="item.title" v-for="(item,index) in peoplelist" :key="index" >
                        <el-input v-model="item.ticket_personal_num" placeholder="必填" :disabled="true"></el-input>
                    </el-form-item>

                 </el-row> 
               </el-form>

            </div> 
        </el-dialog>

      
  </div>
</template>

<script>
import LandList from '@/view/Jindou/LandList'
export default {
  name: 'land',
  data () {
    return {
        landdata:[],
        page:1,
        count:0,
        mtk1:false,
        search_form:{
            onedate:'',
            select_num:'',
        },
        from:{
            pitch:[],
            pitchsrc:'',
            pitch_list:[],
            time1:'',
            time2:'',
            exchange_times:'',
        },
        user_test:{  //用户判定
            user_mtk:false, //用户判定模态狂
            codeText:'获取验证码', //获取验证码字
            totalTime:60,  //获取验证码秒
            disabled:false, //禁用获取验证码
            password:'', //二级密码
            phone:'',  //验证码
        },
        jindoujuan:0,
        people_mtk:false,
        peoplelist:[]
    }
  },
 components:{
    LandList
  },
  created(){
       this.list_zy()
       this.list_fun()
  },
  mounted (){
    
  },
  methods: {
    list_zy(){
      this.post("/manor/manorOption", {

       }).then(res => { 
          this.from.pitch_list = res.result              

          for(let b of this.from.pitch_list) {                    
              b.type = true  //默认禁用 
              b.number = ''    //默认禁用input为0            
          }               
           //console.log(res)               
       })
    },
    list_fun(){
      
        this.post("/gdb/listOfGenerate", {
              page:this.page,
              onedate:this.search_form.onedate,
              maid:this.search_form.select_num
	        }).then(res => {
            this.count = res.result.count
            this.landdata = res.result.list
            this.jindoujuan = res.result.jindoujuan
            console.log(res,"aaa")
         })

    },
    land_but(){
          this.mtk1 = true
        //  this.user_test.user_mtk = true
         this.list_zy()
         this.from.pitch = []
         this.from.time1 = ''
         this.from.time2 = ''
    },
    user_mtk_but(){

        this.getCode_yz_qr().then(res => {
            console.log(res)
            if(res == 1){
               this.sub_but_qr()
            }
        })
  
    },
    sub_but(){
       this.user_test.user_mtk = true
    },
    sub_but_qr(){
 
        let arra =[]
        //console.log(this.from.pitch_list)

        for(let b of this.from.pitch_list) {   
            if(b.number != ''){
              let item = {'count':b.number,'maid':b.maid}
               arra.push(item)       
            }                                                     
        } 

         
        this.post("/gdb/generateGoods", {
              arr:arra,
              manor_id:arra[0].maid,
              start:this.from.time1,
              end:this.from.time2,
              exchange_times:this.from.exchange_times
          }).then(res => {

              if(res.error_code == 0){
              this.open1(res.result,'success')  //提示框
              this.list_fun()
              this.mtk1 = false
              }else {
              this.open1(res.message,'warning')
          }

        })

        //console.log(arra)
        
    },
    select_change(val){       
        //console.log(val)
        this.from.pitch = []
        this.from.pitch.push(this.from.pitchsrc)
        console.log(this.from.pitch)

        for(let b of this.from.pitch_list) { //默认禁用                       
            b.type = true                                       
        } 
        for(let a of this.from.pitch){             
            for(let b of this.from.pitch_list) {                
                  if(a == b.maid ){ //判断是否包含maid  包含开启输入
                    b.type = false
                  }                        
            } 
        } 
        for(let b of this.from.pitch_list) {                           
            if(b.type == true ){  //禁用的input为0
                b.number = ''
            }                                      
        }   

        //console.log(this.from.pitch_list)

    },
    people_fun(){
       this.post("/gdb/holdTicketOfManor", {

       }).then(res => { 
            this.peoplelist = res.result      
           console.log(res,"sss")               
       })
    },
    people_but(){
      //  this.people_mtk = true
      //  this.people_fun()
      this.$router.push({
          path: '/index/certificate',
          query: {
          }
        })
    },
    change_input(e){  //防止input输入不进去
         this.$forceUpdate()
    },
    go_land_xq(){
       this.$router.push({
          path: '/index/landxq',
          query: {
            name:"标的详情",
            gid:'',
            start:'',
            end:'',
          }
        })
    },
    search_but(){
      this.page = 1

      this.list_fun()
    },
    sx_but(){
      this.page = 1

      this.search_form={
        onedate:'',
        select_num:'',
      },

      this.list_fun()
    },
     handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
      },
      handleCurrentChange(val) {
        this.page = val
        this.list_fun()
        console.log(`当前页: ${val}`);
      }
  }
}
</script>


<style scoped>
.mytitle{
    height: 50px;
}
.mytitle_item{
    display: flex;
    align-items: center;
}
.mytitle_item::before{
  content:'';
  width: 5px;
  height: 15px;
  background: #409EFF;
  display: block;
  margin-right: 5px;
}
.buttoon_box{
  display:flex;margin-bottom:10px;
}
.buttoon_box_item{
  height:40px;line-height:40px;width:60px;font-size:14px;text-align:center;border-radius:5px;
}
.el-input-box>>>input{
  padding: 0px 3px !important;
}
</style>
